<template>
	<view class="mainpadding">
		<view class="flexcenter" v-if="!list.data.length">
			<view class="placeholderimage" style="margin-top: 300rpx;" ></view>
		</view>
		<view class="mainpadding radius margin_top ffffff" v-else v-for="item in list.data" :key="item.id" @click="tzggxq(item.id)">
			<view class="ershil xiaohei nofonweight yhxk">{{item.title}}</view>
			<view class="strongtext xiaohui nofonweight margin_top1">{{returnDate(item.createtime * 1000)}}</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				httpRequest:httpRequest	,
				page: 1,
				limit: 12,
				list: {
					data: []
				},
			}
		},
		onLoad(options) {
			this.type = options.type
			this.init()
		},
		methods: {
			returnDate(timer) {
				var date = new Date(timer); //当前时间
				var year = date.getFullYear() //返回指定日期的年份
				var month = repair(date.getMonth() + 1); //月
				var day = repair(date.getDate()); //日
				var curTime = year + "-" + month + "-" + day
			
				function repair(i) {
					if (i >= 0 && i <= 9) {
						return "0" + i;
					} else {
						return i;
					}
				}
				return curTime
			},
			init(isPage, page) {
				let _this = this;
				let data = {
					page: page || 1,
					limit: _this.limit,
				}
				let url = '/api/index/niticeindex'
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			// 跳转公告详情
			tzggxq(id) {
				uni.navigateTo({
					url: '/pages/mypage/gonggaoxq?id='+id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.margin_top:first-child {
		margin-top: 0;
	}

	page {
		background: #F9F9F9;
	}
</style>